Difference between Node require and ES6 import and export
Node.js uses the CommonJS module system to organize code. This means when you want to use code from other files, you use methods like ‘require’. Additionally, Node.js also supports ‘ES6 import and export’ for this purpose. Let us understand in detail....
read more
Difference between tilde ( ~ ) and caret ( ^ ) in package.json
When we open our package.json file and search for the dependency property and in there we find the packages that are listed as a nested object of the dependency property package-name:package-version. Now look at the package version, we find some numbers separated by three dots....
read more
Maximum product of a pair of nodes from largest connected component in a Graph
Given an undirected weighted graph G consisting of N vertices and M edges, and two arrays Edges[][2] and Weight[] consisting of M edges of the graph and weights of each edge respectively, the task is to find the maximum product of any two vertices of the largest connected component of the graph, formed by connecting all edges with the same weight....
read more
Traverse graph in lexicographical order of nodes using DFS
Given a graph, G consisting of N nodes, a source S, and an array Edges[][2] of type {u, v} that denotes that there is an undirected edge between node u and v, the task is to traverse the graph in lexicographical order using DFS....
read more
Make given segments non-overlapping by assigning directions
Given an array arr[][] consisting of N segments of the form {L, R, V} where, [L, R] denotes a segment with velocity V in any direction, the task is to check if it is possible to assign directions as left or right to all the segments such that they do not intersect after a long period of time....
read more
Maximum time required for all patients to get infected
Given a matrix arr[][], consisting of only 0, 1, and 2, that represents an empty ward, an uninfected patient, and an infected patient respectively. In one unit of time, an infected person at index (i, j) can infect an uninfected person adjacent to it i.e., at index (i – 1, j), (i + 1, j), (i, j – 1), and (i, j + 1). The task is to find the minimum amount of time required to infect all the patients. If it is impossible to infect all the patients, then print “-1”....
read more
Check if a directed graph is connected or not
Given a directed graph. The task is to check if the given graph is connected or not.Examples:...
read more
CPU Scheduling in Operating Systems
Scheduling of processes/work is done to finish the work on time. CPU Scheduling is a process that allows one process to use the CPU while another process is delayed (in standby) due to unavailability of any resources such as I / O etc, thus making full use of the CPU. The purpose of CPU Scheduling is to make the system more efficient, faster, and fairer....
read more
Minimize cost to color all the vertices of an Undirected Graph
Given an Undirected Graph consisting of N vertices and M edges, where node values are in the range [1, N], and vertices specified by the array colored[] are colored, the task is to find the minimum color all vertices of the given graph. The cost to color a vertex is given by vCost and the cost to add a new edge between two vertices is given by eCost. If a vertex is colored, then all the vertices that can be reached from that vertex also become colored....
read more
Nodes with prime degree in an undirected Graph
Given an undirected graph with N vertices and M edges, the task is to print all the nodes of the given graph whose degree is a Prime Number.Examples:...
read more
Check if a given Graph is 2-edge connected or not
Given an undirected graph G, with V vertices and E edges, the task is to check whether the graph is 2-edge connected or not. A graph is said to be 2-edge connected if, on removing any edge of the graph, it still remains connected, i.e. it contains no Bridges....
read more
Minimum Cost using Dijkstra by Modifying Cost of an Edge
Given an undirected weighted graph of N nodes and M edges in the form of a tuple lets say {X, Y, Z} such that there is an edge with cost Z between X and Y. We are supposed to compute the minimum cost of traversal from node 1 to N. However, we can perform one operation before the traversal such that we can reduce the cost of any edge lets say, C to C / 2 (integer division)....
read more